
<html>
<head>
	<meta charset="UTF-8">
	<title>外部模型数据赋值修改</title>
	<link id="easyuiTheme"  href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/css/esaas-easyui-add.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
<style>
	body {
		overflow: auto !important
	}
	#ff table td {
		vertical-align:top
	}
</style>
</head>
<body class="easyui-layout" scroll="no">
	<form id="ff" method="post">
		<div class="esaas-info-title">外部模型数据赋值信息</div>
		<table class="esaas-info-edit-table">
			<tr hidden="true">
				<td width="15%" align="right">赋值标识：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="recordKeyid" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
					<td width="15%" align="right">节点标识：</td>
					<td width="35%"><input class="easyui-textbox" type="text" 
						name="nodeId" data-options="required:false" id="nodeId"
						style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="left">赋值目标类型：</td>
				
				<td width="15%" align="left">赋值字段：</td>
				
				<td width="15%" align="left">赋值方法：</td>
				
			</tr>
			<tr>
				<td width="35%"><select class="easyui-combobox"
					id="tranTargetType" name="tranTargetType"
					style="width: 100%; height: 25px;"
					data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:TRAN_TARGET_TYPE,onChange:tranTypeChange">
				</select></td>
				<td width="35%">
					<ul class="easyui-datalist" id="tranFieldCodeList" data-options="valueField:'paramFieldCode', textField:'text'"></ul>
				</td>
				<td width="35%"><select class="easyui-combobox"
					id="tranFuncId" name="tranFuncId"
					style="width: 100%; height: 25px;"
					data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:TRAN_FUNC_ID">
				</select></td>
			</tr>
			<tr hidden="true">
				<td width="15%" align="right">赋值字段名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="fieldName" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				
			</tr>
		</table>
	</form>
	<div style="text-align: center; padding: 15px">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			onclick="submitForm()">&nbsp;保&nbsp;存&nbsp;</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>
	<script>
		var appId = $.getUrlParam('appId');
		var nodeId = $.getUrlParam('nodeId');
		var appModelId = $.getUrlParam('appModelId');
		var tran = null;
		$(function() {
			var recordKeyid = $.getUrlParam('recordKeyid');
			$.restfulGet('../../api/osrv/tran/info/' + recordKeyid,null,function(data){
				tran = data.rows;
					$('#ff').form('load', {
						recordKeyid : data.rows.recordKeyid,
						nodeId : data.rows.nodeId,
						fieldCode : data.rows.fieldCode,
						tranTargetType : data.rows.tranTargetType,
						fieldType : data.rows.fieldType,
						fieldName : data.rows.fieldName,
						tranFuncId : data.rows.tranFuncId
					});					
			});
		});
	
		function submitForm() {
			if (!$('#ff').form('validate'))
				return;
			var jsonData = $("#ff").serializeJson();
			
			var tranFieldSelected = $('#tranFieldCodeList').datagrid('getSelected');
			if (!tranFieldSelected) {
				$.messager.alert('提示','请选择一条赋值字段！','info');
				return;
			}
			var jsonData = $("#ff").serializeJson();
			jsonData.fieldCode = tranFieldSelected.paramFieldCode;
			jsonData.fieldName = tranFieldSelected.paramFieldName
			
			$.restfulPut('../../api/osrv/tran/info', jsonData, function(data) {
				window.parent.reloadList();
			});
		};

		function tranTypeChange(newValue, oldValue) {
			var selectIndex = -1, fieldCode = tran.fieldCode;
			
			var ioType =  "I" 
			$.restfulPostForm(`../../api/osrv/inout/infos`, {
				ioType: ioType,
				appModelId : appModelId
			}, function(data){
				data.rows.forEach((f, index) =>{
					f.text = `${f.paramFieldCode} ${f.paramFieldName ? f.paramFieldName: "" }`
					if (fieldCode && fieldCode == f.paramFieldCode) {
						selectIndex = index
					}
				})
				$('#tranFieldCodeList').datalist({data: data.rows})
				if (selectIndex != -1 ) {
					$('#tranFieldCodeList').datalist('selectRow', selectIndex)
				}
			})
			
		}
		
		function closeForm(){
			window.parent.JLEUtil.closewin();
		}
	</script>
</body>
</html>
